package com.smartleanx.module.hrm.controller.app.eagin;

import com.smartleanx.framework.common.pojo.CommonResult;
import com.smartleanx.module.hrm.service.esign.auth.IElecCorpService;
import com.smartleanx.module.hrm.service.esign.bo.ElecCorpCreateBo;
import com.smartleanx.module.hrm.service.esign.bo.ElecCorpSelectBo;
import com.smartleanx.module.hrm.service.esign.bo.ElecCorpUpdateBo;
import com.smartleanx.module.hrm.service.esign.bo.OrgIdentifyBo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

import static com.smartleanx.framework.common.pojo.CommonResult.success;


/**
 * @author yanglihao
 */
@Api(tags = "企业管理")
@RestController
@RequestMapping("/hrm/app/elec/corp")
@AllArgsConstructor
public class ElecCorpAppController {

    private IElecCorpService elecCorpService;

    @ApiOperation("企业列表")
    @GetMapping("/page")
    public CommonResult<Object> page(ElecCorpSelectBo param) {
        return success(elecCorpService.page(param));
    }
    @ApiOperation("企业下拉")
    @GetMapping("/bySelect")
    public CommonResult<Object> bySelect() {
        return success(elecCorpService.corpBySelect());
    }

    @ApiOperation("员工在企业中的权限")
    @GetMapping("/permission")
    public CommonResult<Object> permission(@RequestParam long corpId) {
        return success(elecCorpService.permission(corpId));
    }

    @ApiOperation("企业详情")
    @GetMapping("/detail")
    public CommonResult<Object> detail(@RequestParam long corpId) {
        return success(elecCorpService.detail(corpId));
    }

    @ApiOperation("新增企业")
    @PostMapping("/create")
    public CommonResult<Object> create(@RequestBody @Valid ElecCorpCreateBo param) {
        elecCorpService.create(param);
        return success("创建成功");
    }

    @ApiOperation("编辑详情")
    @GetMapping("/update")
    public CommonResult<Object> update(@RequestParam long corpId) {
        return success(elecCorpService.update(corpId));
    }

    @ApiOperation("编辑保存")
    @PostMapping("/update")
    public CommonResult<Object> update(@RequestBody @Valid ElecCorpUpdateBo param) {
        elecCorpService.update(param);
        return success("修改成功");
    }

    @ApiOperation("删除企业")
    @DeleteMapping("/remove")
    public CommonResult<Object> remove(@RequestParam long corpId) {
        elecCorpService.remove(corpId);
        return success("删除成功");
    }

    @ApiOperation("企业认证")
    @PostMapping("/identify")
    public CommonResult<Object> identify(@RequestBody OrgIdentifyBo param) {
        return success(elecCorpService.identify(param));
    }
}
